from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from ..websockets.manager import manager 

router = APIRouter()
 
@router.websocket("/client/{id}")
async def client_websocket_endpoint(websocket: WebSocket,id:str): 
    # 服务器生成连接ID
    connection_id = await manager.connect_client(websocket,id)
    try:
        # 发送连接ID给客户端
        await websocket.send_json({"type": "connection_id", "connection_id": connection_id})
        
        while True:
            # 保持连接活跃
            data = await websocket.receive_text()
            # 这里可以处理来自客户端的消息，如果需要的话
    except WebSocketDisconnect:
        manager.disconnect_client(connection_id)

 